USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Insert]    Script Date: [[20120914064951]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064951]]
-- Description:	Insert record into table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Bank_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Dealer_Bank_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers_Banks](/*[ID], [Dealer_ID], [Bank_ID], [AcountNumber]*/)
	VALUES     (/*@ID, @Dealer_ID, @Bank_ID, @AcountNumber*/)

	/*SELECT @RowNumber = [RowNumber], @Dealer_Bank_TimeStamp = [Dealer_Bank_TimeStamp]
    FROM [dbo].[Dealers_Banks]
    WHERE  ( [ID] =@ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Bank_ID] =@Bank_ID )
	AND  ( [AcountNumber] =@AcountNumber )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-update]    Script Date: [[20120914064951]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064951]]
-- Description:	Update record in table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Bank_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Dealer_Bank_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Dealer_Bank_TimeStamp]
    FROM [dbo].[Dealers_Banks]
    	WHERE ([ID] = @ID)

    IF  @OldTimeStamp = @Dealer_Bank_TimeStamp
    BEGIN*/
		Update [dbo].[Dealers_Banks] SET 
		/*[ID] =@ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Bank_ID] =@Bank_ID, 
		[AcountNumber] =@AcountNumber*/
		/*WHERE ([ID] = @ID)*/
	/*END*/

	/*SELECT @RowNumber = [RowNumber], @Dealer_Bank_TimeStamp = [Dealer_Bank_TimeStamp]
    FROM [dbo].[Dealers_Banks]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Insert-Update]    Script Date: [[20120914064951]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064951]]
-- Description:	Insert OR Update record into table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Bank_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Dealer_Bank_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers_Banks] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers_Banks](/*[ID], [Dealer_ID], [Bank_ID], [AcountNumber]*/)
		VALUES     (/*@ID, @Dealer_ID, @Bank_ID, @AcountNumber*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Dealer_Bank_TimeStamp]
		FROM [dbo].[Dealers_Banks]
    	WHERE ([ID] = @ID)

		IF  @OldTimeStamp = @Dealer_Bank_TimeStamp
		BEGIN*/
			Update [dbo].[Dealers_Banks] SET 
			/*[ID] =@ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Bank_ID] =@Bank_ID, 
			[AcountNumber] =@AcountNumber*/
			/*WHERE ([ID] = @ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber], @Dealer_Bank_TimeStamp = [Dealer_Bank_TimeStamp]
    FROM [dbo].[Dealers_Banks]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Delete]    Script Date: [[20120914064952]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064952]]
-- Description:	delete records from table [dbo].[Dealers_Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@AcountNumber varchar(100) =null  , 
	@Dealer_Bank_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers_Banks]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [AcountNumber] like ISNULL(@AcountNumber, [AcountNumber]) )
	AND ( [Dealer_Bank_TimeStamp] = ISNULL(@Dealer_Bank_TimeStamp, [Dealer_Bank_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Select]    Script Date: [[20120914064952]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064952]]
-- Description:	select records from table [dbo].[Dealers_Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@AcountNumber varchar(100) =null  , 
	@Dealer_Bank_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers_Banks]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [AcountNumber] like ISNULL(@AcountNumber, [AcountNumber]) )
	AND ( [Dealer_Bank_TimeStamp] = ISNULL(@Dealer_Bank_TimeStamp, [Dealer_Bank_TimeStamp]) )*/
END
GO
-- =============================================
